<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html>
<head>
</head>
<body>

<button id="button1" class='btn btn-default' >ajax-json-str</button>subimt  list&lt;T&gt; type data
<button id="button2" class='btn btn-default' >submit</button>
<script>
	$('#button1').click(function() {
		var data = [{username:'zhangsan'},{username:'lisi'}];
		var str = JSON.stringify(data);
		$.ajax({
			url : '${contextPath}/userController/submitData.do',
			type : 'post',
			data : str,
			dataType:'json',
			contentType : 'application/json;charset=utf-8',
			success:function(result){
				alert(result);
			}
		});
	});
	
	$('#button2').click(function() {
		var data = [{username:'zhangsan'},{username:'lisi'}];
		var formId = "__downloadForm";
		var form = document.getElementById(formId);
		if (form == null) {
			form = document.createElement("form");
			form.id = formId;
			form.style.display = "none";
			document.body.appendChild(form);
			form.method = 'post';
		} else {
			form.innerHTML = "";
		}
		form.action = "${contextPath}/userController/submitData3.do"; 
		form.target = "_self";
		 for(var i in data){
			var el = document.createElement("input");
			el.setAttribute("id", formId + i);
			el.setAttribute("name", "list["+i+"].username");
			el.setAttribute("type", "hidden");
			form.appendChild(el);
			document.getElementById(formId + i).value = data[i].username;
		}
		//form.ba = JSON.stringify(data);
		form.submit();
	});
	
</script>
</body>
</html>